/**
 * Created by charlie on 17-12-27.
 */
import {seeDetail} from '../services/taiZhangDetail'
export default {
    namespace:'taiZhangDetail',
    state:{
        data:{},
        prjname:'',
        corpName:'',
        img:[],
        createDate:'',
        loading:true,
        imgUrl:'',
        thisOpen:false
    // changeFormCorpSigns 企业签字
    },
    subscriptions:{

    },
    effects:{
        *getTaiZhangDetail({payload},{put,select,call}){
            yield put({type:'thisInit'});
            const {id} = yield  select(state => state.taiZhang)
            const { json, error } = yield call(seeDetail, {changeFormId: id})

            if(error){
                // console.log('获取台账记录详情错误,错误内容: ' + error)
                yield put({type: 'getLoading'})

            }else{
                console.log(json,'taizhnag')
                yield put({type: 'thisSuccess', payload: json.data})
            }
        }

    },
    reducers:{
        thisInit(state,{payload}){
            return {...state,data:{},prjname:'',img:[],createDate:''}
        },
        thisSuccess(state,{payload}){
            let thisImg = [];
            let createDate ='';
            payload.changeFormImgs.map(val => {
                thisImg.push({img: val.url});
            });
            if(payload.createDate.length >10){
                createDate = payload.createDate.substring(0,10);
            }else {
                createDate = payload.createDate;
            }
            return {...state,data:payload,prjname:payload.prjName,img:thisImg,createDate:createDate,
                    loading:false,corpName:payload.corpName}
        },
        getLoading(state,{payload}){
            return{...state,loading:false}
        },
        getClean(state,{payload}){
            return{...state,loading:true}
        },
        thisPhotoOpen(state,{payload}){
            return{...state,
                imgUrl:payload,
                thisOpen:true
            }
        },
        thisPhotoClose(state,{payload}){
            return{...state,
                imgUrl:'',
                thisOpen:false
            }
        },
    }
}